from rest_framework import serializers
from . import models


class AdminArticleSortSerializer(serializers.ModelSerializer):
    group = serializers.IntegerField(default=1, write_only=True)

    class Meta:
        model = models.Sort
        fields = ['id', 'name', 'ord', 'pid', 'is_active', 'group']

        extra_kwargs = {
            'id': {'read_only': True},
        }

    # 局部钩子
    def validate_group(self, item):
        if item != 1:
            item = 1
        return item
